﻿using BPMS.Business;
using BPMS.Entity;
using BPMS.IBusiness;
using DotNet.Utilities;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace BPMS.MVC.Controllers
{
    public class LogController : BaseController
    {
        BPMS_SysLogIBLL bpms_syslogsibll = new BPMS_SysLogBLL();

        #region 登录日志
        /// <summary>
        /// 登录日志
        /// </summary>
        /// <returns></returns>
        public ActionResult LoginLogList()
        {
            ViewBag.start_Date = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd 00:00");
            ViewBag.end_Date = DateTime.Now.ToString("yyyy-MM-dd 23:59");
            return View();
        }
        /// <summary>
        /// 处理数据
        /// </summary>
        public void LoadAction()
        {
            string active = Request["action"];                                          //提交类型
            int pageIndex = CommonHelper.GetInt(Request["pqGrid_PageIndex"]);           //当前页
            int pageSize = CommonHelper.GetInt(Request["pqGrid_PageSize"]);             //当前页大小
            string orderField = Request["pqGrid_OrderField"];                           //排序字段  
            string orderType = Request["pqGrid_OrderType"];                             //排序类型
            string pqGrid_Sort = Request["pqGrid_Sort"];                                //要显示字段
            string key = Request["key"];                                                //主键
            string Parm_Key_Value = Request["Parm_Key_Value"];                          //搜索条件键值
            switch (active)
            {
                case "GridBindList"://加载列表
                    int count = 0;
                    Hashtable parm = HashtableHelper.String_Key_ValueToHashtable(Parm_Key_Value);
                    Response.Write(JsonHelper.PqGridPageJson<BPMS_SysLoginLog>(bpms_syslogsibll.GetLoginLogList(parm, orderField, orderType, pageIndex, pageSize, ref count), pageIndex, pqGrid_Sort, count));
                    Response.End();
                    break;
                default:
                    break;
            }
        }
        #endregion

        #region 删除日志
        /// <summary>
        /// 登录日志
        /// </summary>
        /// <returns></returns>
        public ActionResult DeleteLog()
        {
            return View();
        }
        /// <summary>
        /// 删除日志确认事件
        /// </summary>
        /// <param name="KeepTime">日志保留时间</param>
        /// <param name="type">1:登录日志，2：操作日志</param>
        public ActionResult AcceptDeleteLog(string KeepTime, string type)
        {
            bool IsOk = false;
            if (type == "2")
            {
                IsOk = bpms_syslogsibll.EmptyLog(KeepTime);//清空操作日志
            }
            else
            {
                IsOk = bpms_syslogsibll.EmptyLoginLog(KeepTime);//清空登录日志
            }
            return Content(IsOk.ToString().ToLower());
        }
        #endregion

        #region 操作日志列表
        /// <summary>
        /// 操作日志列表
        /// </summary>
        /// <returns></returns>
        public ActionResult LogList()
        {
            ViewBag.start_Date = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd 00:00");
            ViewBag.end_Date = DateTime.Now.ToString("yyyy-MM-dd 23:59");
            return View();
        }
        /// <summary>
        /// 处理数据
        /// </summary>
        public void LoadAction_LogList()
        {
            string active = Request["action"];                                          //提交类型
            int pageIndex = CommonHelper.GetInt(Request["pqGrid_PageIndex"]);           //当前页
            int pageSize = CommonHelper.GetInt(Request["pqGrid_PageSize"]);             //当前页大小
            string orderField = Request["pqGrid_OrderField"];                           //排序字段  
            string orderType = Request["pqGrid_OrderType"];                             //排序类型
            string pqGrid_Sort = Request["pqGrid_Sort"];                                //要显示字段
            string key = Request["key"];                                                //主键
            string Parm_Key_Value = Request["Parm_Key_Value"];                          //搜索条件键值
            switch (active)
            {
                case "GridBindList"://加载列表
                    int count = 0;
                    Hashtable parm = HashtableHelper.String_Key_ValueToHashtable(Parm_Key_Value);
                    Response.Write(JsonHelper.PqGridPageJson<BPMS_SysLogs>(bpms_syslogsibll.GetLogList(parm, orderField, orderType, pageIndex, pageSize, ref count), pageIndex, pqGrid_Sort, count));
                    Response.End();
                    break;
                default:
                    break;
            }
        }
        #endregion

        #region 操作日志明细
        /// <summary>
        /// 操作日志明细
        /// </summary>
        /// <returns></returns>
        public ActionResult LogDetail()
        {
            return View();
        }
        #endregion
    }
}
